package ice.server.comm;

import ice.tool.GsonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by 老王 on 2018/3/1.
 * 操作型接口返回结果
 */
public class BaseOperateResult {

    private static Logger log = LoggerFactory.getLogger(BaseOperateResult.class);

    private int type;
    private String typecode;
    private String title;
    private String message;
    private Object data;

    public BaseOperateResult() {

    }

    public BaseOperateResult(int type, String typecode, String title, String message, Object data) {
        this.type = type;
        this.typecode = typecode;
        this.title = title;
        this.message = message;
        this.data = data;
    }

    /**
     * 操作成功，带有返回参数
     */
    public static BaseOperateResult success(String message,Object data){
        return new BaseOperateResult(1,"success","",message,data);
    }
    /**
     * 操作成功，不带有返回参数
     */
    public static BaseOperateResult success(String message){
        return new BaseOperateResult(1,"success","",message,null);
    }
    /**
     * 操作失败，不带有返回参数
     */
    public static BaseOperateResult error(String message,Object data){
        return new BaseOperateResult(2,"error","",message,data);
    }
    /**
     * 操作失败，不带有返回参数
     */
    public static BaseOperateResult error(String message){
        return error(message, null);
    }
    /**
     * 操作警告，不带有返回参数
     */
    public static BaseOperateResult warning(String message,Object data){

        return new BaseOperateResult(3,"warning","",message,data);
    }
    /**
     * 操作警告，不带有返回参数
     */
    public static BaseOperateResult warning(String message){
        return warning(message, null);
    }
    /**
     * 新增操作
     */
    public static BaseOperateResult add(Integer id){
        return id>0?new BaseOperateResult(1,"success","","新增成功",null):new BaseOperateResult(3,"error","","新增失败",null);
    }
    /**
     * 修改操作
     */
    public static BaseOperateResult update(Integer id){
        return id>0?new BaseOperateResult(1,"success","","修改成功",null):new BaseOperateResult(3,"error","","修改失败",null);
    }
    /**
     * 删除操作
     */
    public static BaseOperateResult delete(Boolean flag){
        return flag?new BaseOperateResult(1,"success","","删除成功",null):new BaseOperateResult(3,"error","","删除失败",null);
    }


    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getTypecode() {
        return typecode;
    }

    public void setTypecode(String typecode) {
        this.typecode = typecode;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return GsonUtil.ObjToString(this);
    }
}
